import requests from "./ajax";
import mockRequests from "./mockAjax"
import { Configuration, OpenAIApi } from "openai";

// 向后端请求
export const reqAnswer = question => requests({
    url: '/react',
    method: 'get',
    params: question
})
// 测试请求
export const reqTest = question => mockRequests({
    url: '/test',
    method: 'get',
    params: question    //传入一个对象 { number: 5, name: xxx}
})
// 调用OpenAI接口
export async function callOpenAI(question) {
    const configuration = new Configuration({
        apiKey: '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',
    });
    const openai = new OpenAIApi(configuration);

    const completion = await openai.createChatCompletion({
        model: "gpt-3.5-turbo",
        messages: [{ role: "user", content: question }],
    });
    return completion.data.choices[0].message.content;
}